package world0;

import java.util.ArrayList;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

public class Player extends GenericChar {

	private Image image2;
	
	public Player(float x, float y, Image image, int index) throws SlickException {
		super(x, y, image.getSubImage(0,0,32,64), index, 1);
		image2 = image.getSubImage(0,0,32,64);
		
		setName("staxx6");
		setSpeed(1.0f);
		setRandomWalk(false);
		setMaxJump(100);
		setHoldItems(true);
		
		super.setStartSpeed(getSpeed() / 3);
		super.setAccelration(getSpeed() / 200);
		super.setSpeedResetValue(3);
		
		skill.setSwordSkill(1);
	}
	
	@Override
	public void draw(Graphics g) throws SlickException {

		if(isAttitude()) {
			g.setColor(Color.blue);
		} else {
			g.setColor(Color.red);
		}
		
		image2.drawCentered(getX(), getY());
		
		String info = "Live: " + getLive() + " lvl: " + skill.getLevel();
		g.drawString(info, getX() - (g.getFont().getWidth(info) / 2),
				getY() - 50);
		g.drawString(getName(), getX() - (g.getFont().getWidth(getName()) / 2),
				getY() - 70);

		//collision.debugDraw(g);
	} 
	
	public void update(int delta, Input input, ArrayList<LevelObject> solidList,
	ArrayList<LevelObject> slopeList) {
		if(!isFly()) {
			bodyFall(getSpeed(), getFallSpeed(), solidList, slopeList);
		}
		
		if(input.isKeyPressed(Input.KEY_W)) {
			jump(getFallSpeed(), getMaxJump(), solidList, slopeList);
		}
		
		if(input.isKeyDown(Input.KEY_A)) {
			moveLeft(getSpeed(), solidList, slopeList);
		}
		
		if(input.isKeyDown(Input.KEY_D)) {
			moveRight(getSpeed(), solidList, slopeList);
		}
		
		if (!(input.isKeyDown(Input.KEY_RIGHT)) && !(input.isKeyDown(Input.KEY_D)) &&
				!(input.isKeyDown(Input.KEY_LEFT)) && !(input.isKeyDown(Input.KEY_A))) {
			resetSpeed(getSpeed());
		}
		
		if(input.isKeyDown(Input.KEY_LCONTROL) && input.isKeyPressed(Input.KEY_R)) {
			resetChar();
		}
		
		if(input.isKeyPressed(Input.KEY_R)) {
			resetPosition();
		}
		
		if(input.isKeyDown(Input.KEY_L) && input.isKeyPressed(Input.KEY_1)) {
			skill.setSwordSkill(skill.getSwordSkill() + 1);
		}
		
		if(input.isKeyDown(Input.KEY_L) && input.isKeyPressed(Input.KEY_2)) {
			skill.setTwoHandSwordSkill(skill.getTwoHandSwordSkill() + 1);
		}
		
		if(input.isKeyDown(Input.KEY_L) && input.isKeyPressed(Input.KEY_3)) {
			skill.setTwoOneHandSword(skill.getTwoOneHandSword() + 1);
		}
				
		super.update(getSpeed(), solidList, slopeList);		
	}
	
}
